package com.goldman.aplt.util;

import lombok.extern.slf4j.Slf4j;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @description：
 * @author： chenxiangxiang
 * @create： 2023/12/1 17:50
 */
@Slf4j
public class TokenUtil {
    public static String generateKycRequestToken(String originalText) {
        String mySignature;
        try {
            MessageDigest md = MessageDigest.getInstance("SHA1");
            md.update(originalText.getBytes());
            byte[] digest = md.digest();

            StringBuffer hexstr = new StringBuffer();
            String shaHex = "";
            for (int i = 0; i < digest.length; i++) {
                shaHex = Integer.toHexString(digest[i] & 0xFF);
                if (shaHex.length() < 2) {
                    hexstr.append(0);
                }
                hexstr.append(shaHex);
            }
            mySignature = hexstr.toString();
            return mySignature;
        } catch (NoSuchAlgorithmException e) {
            log.error("kyc request token generate failure", e);
        }
        return "";
    }
}
